home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Format (PL) 2008 December
/
PC_Format_122008.iso
/
Multimedia
/
MediaPortal 0.2.3.0
/
MediaPortal_0.2.3.0_Setup.exe
/
scripts
/
imdb
/
mymovies_it.csscript
< prev
next >
Wrap
Text File
|
2007-10-20
|
17KB
|
493 lines
//css_reference "core.dll";
//css_reference "Databases.dll";
//css_reference "utils.dll";
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Collections;
using System.Web;
using System.Text.RegularExpressions;
using MediaPortal.Util;
class Grabber : MediaPortal.Video.Database.IIMDBScriptGrabber
{
public Grabber()
{
}
void MediaPortal.Video.Database.IIMDBScriptGrabber.FindFilm(string strSearch, int iLimit, ArrayList elements)
{
int iCount = 0;
string strTitle;
try
{
string absoluteUri;
string strURL = "http://www.mymovies.it/database/ricerca/avanzata/?titolo=" + strSearch + "&titolo_orig=®ista=&attore=&id_genere=-1&nazione=&clausola1=-1&anno_prod=&clausola2=-1&stelle=-1&id_manif=-1&anno_manif=&disponib=-1&ordinamento=1&submit=Inizia+ricerca+%BB";
string strBody = GetPage(strURL, "utf-8", out absoluteUri);
// Mars Warrior @ 03-sep-2004.
// First try to find an Exact Match. If no exact match found, just look
// for any match and add all those to the list. This narrows it down more easily...
int iStartOfMovieList = strBody.IndexOf("<div class=\"sezione\">Film</div>");
int endOfTitleList = strBody.IndexOf("<div style=\"height:20px; clear:both;\"></div>");
if (iStartOfMovieList < 0)
{
return;
}
iStartOfMovieList += "<div class=\"linkblu\" style=\"padding:3px;\">".Length;
int iEndOfMovieList = strBody.IndexOf("<div style=\"height:20px; clear:both;\"></div>", iStartOfMovieList);
if (iEndOfMovieList < 0)
{
iEndOfMovieList = strBody.Length;
}
if (endOfTitleList < iEndOfMovieList && endOfTitleList > iStartOfMovieList)
{
iEndOfMovieList = endOfTitleList;
}
strBody = strBody.Substring(iStartOfMovieList, iEndOfMovieList - iStartOfMovieList);
while ((true) && (iCount < iLimit))
{
////<A HREF="/Title?0167261">Lord of the Rings: The Two Towers, The (2002)</A>
int iAHREF = strBody.IndexOf("<a href=");
if (iAHREF >= 0)
{
int iEndAHREF = strBody.IndexOf("</a>");
if (iEndAHREF >= 0)
{
iAHREF += "<a href=.".Length;
string strAHRef = strBody.Substring(iAHREF, iEndAHREF - iAHREF);
int iURL = strAHRef.IndexOf("\" title");
if (iURL > 0)
{
strTitle = "";
strURL = strAHRef.Substring(0, iURL);
if (strURL[strURL.Length - 1] == '\"')
strURL = strURL.Substring(0, strURL.Length - 1);
iURL += "\" title=\"".Length;
int iURLEnd = strAHRef.IndexOf("\">", iURL);
if (iURLEnd > 0)
{
strTitle = strAHRef.Substring(iURL, iURLEnd - iURL);
}
else
strTitle = strAHRef.Substring(iURL);
int iYear = strBody.IndexOf("www.mymovies.it/film/?anno=");
iYear += "www.mymovies.it/film/.anno=".Length;
string strYear = strBody.Substring(iYear, 4);
///int onclick = strURL.IndexOf(" onclick");
///if (onclick >= 0)
/// strURL = strURL.Substring(0, onclick - 1);
/// strURL = String.Format("http://it.movies.yahoo.com{0}", strURL);
HTMLUtil htmlUtil = new HTMLUtil();
htmlUtil.ConvertHTMLToAnsi(strTitle, out strTitle);
///int endTagLength = "</a>".Length;
///int posNextTag = strBody.IndexOf("<", iEndAHREF + endTagLength);
///if (posNextTag > 0)
///{
///string strSub = strBody.Substring(iEndAHREF + endTagLength, posNextTag - (iEndAHREF + endTagLength));
///strTitle += strSub;
///}
// to avoid including of
if ((strTitle.IndexOf("\n") < 0) && (strTitle.IndexOf(" ") < 0))
{
MediaPortal.Video.Database.IMDB.IMDBUrl url = new MediaPortal.Video.Database.IMDB.IMDBUrl(strURL, strTitle + " (" + strYear + ")" + " (mymovies_it)", "mymovies_it");
elements.Add(url);
}
iCount++;
}
if (iEndAHREF + 1 >= strBody.Length)
break;
iStartOfMovieList = iEndAHREF + 1;
iEndAHREF = strBody.IndexOf("<div class=\"tratto\"></div>");
strBody = strBody.Substring(iEndAHREF + 1);
}
else
{
break;
}
}
else
{
break;
}
}
}
catch (Exception ex)
{
MediaPortal.GUI.Library.Log.Error("exception for mymovies lookup of {0} err:{1} stack:{2}",strSearch, ex.Message, ex.StackTrace);
}
}
bool MediaPortal.Video.Database.IIMDBScriptGrabber.GetDetails(MediaPortal.Video.Database.IMDB.IMDBUrl url, ref MediaPortal.Video.Database.IMDBMovie movieDetails)
{
try
{
int iStart = 0;
int iEnd = 0;
movieDetails.Reset();
// add databaseinfo
// may add an another grabber
movieDetails.Database = "mymovies_it";
string strAbsURL;
string strAbsMovieURL;
string strUrlMovieURL;
string strBody = GetPage(url.URL, "utf-8", out strAbsURL);
strAbsMovieURL = strAbsURL;
if (strBody == null || strBody.Length == 0)
return false;
int iPos = strAbsURL.IndexOf("?id=");
if (iPos > 0)
{
iPos += "?id=".Length;
movieDetails.IMDBNumber = strAbsURL.Substring(iPos);
int pos = movieDetails.IMDBNumber.IndexOf(".html");
if (pos > 0)
movieDetails.IMDBNumber = movieDetails.IMDBNumber.Substring(0, pos);
}
int imPos = strAbsMovieURL.IndexOf("mymovies.it");
if (imPos > 0)
{
imPos += "mymovies.it".Length;
strUrlMovieURL = strAbsMovieURL.Substring(imPos);
int posm = strUrlMovieURL.IndexOf("?id=");
if (posm > 0)
strUrlMovieURL = strUrlMovieURL.Substring(0, posm);
}
url.Title = url.Title.Trim();
// cut of " (imdb)"
iEnd = url.Title.IndexOf("[");
if (iEnd >= 0)
{
movieDetails.Title = url.Title.Substring(0, iEnd);
}
else
{
iEnd = url.Title.IndexOf("(");
if (iEnd >= 0)
movieDetails.Title = url.Title.Substring(0, iEnd);
else
movieDetails.Title = url.Title;
}
movieDetails.Title = movieDetails.Title.Trim();
string movieTitle = System.Web.HttpUtility.HtmlEncode(movieDetails.Title);
int iDirectedBy = strBody.IndexOf("Un film di ");
int iCredits = strBody.IndexOf("Sceneggiatura");
int iGenre = strBody.IndexOf("Genere ");
if (iGenre < 0)
iGenre = strBody.IndexOf("Generi");
///int iTagLine = strBody.IndexOf("Tagline:</h5>");
int iPlotOutline = strBody.IndexOf("<strong class=\"courier\" style=\"font-size:23px; margin-bottom:10px; color:#ff0066; display:block;\">");
int iPlotSummary = strBody.IndexOf("<span style=\"font-family:Arial, Sans-Serif; font-size:90%; color:#696969\">");
int iPlot = strBody.IndexOf("<p style=\"text-align:justify;\">");
string strImgAbsURL = "";
string strImgBody = GetPage("http://www.mymovies.it/poster/0/?id=" + movieDetails.IMDBNumber, "utf-8", out strImgAbsURL);
int iImage = strImgBody.IndexOf("alt=\"Locandina");
if (iImage >= 0)
{
iImage = strImgBody.IndexOf("src=\"", iImage);
}
int iRating = strBody.IndexOf("title=\"Valutazione ");
int iCred = strBody.IndexOf("Con ");
///int iTop = strBody.IndexOf("Top 250:");
int iTop = -1;
int iYear = strBody.IndexOf("http://www.mymovies.it/film/?anno=");
if (iYear >= 0)
{
iYear += "http://www.mymovies.it/film/?anno=".Length;
string strYear = strBody.Substring(iYear, 4);
movieDetails.Year = System.Int32.Parse(strYear);
}
if (iDirectedBy >= 0)
movieDetails.Director = ParseAHREFIMDB(strBody, iDirectedBy, url.URL).Trim();
if (iCredits >= 0)
movieDetails.WritingCredits = ParseAHREFIMDB(strBody, iCredits, url.URL).Trim();
if (iGenre >= 0)
{
iGenre += "Genere ".Length;
movieDetails.Genre = ParseGenresIMDB(strBody, iGenre, url.URL).Trim();
}
if (iRating >= 0) // and votes
{
iRating += "title=\"Valutazione ".Length;
iStart = iRating;
if (iStart >= 0)
{
///iStart += "alt=\"".Length;
iEnd = strBody.IndexOf(" stelle", iStart);
// set rating
string strRating = strBody.Substring(iStart, iEnd - iStart);
if (strRating != String.Empty)
strRating = strRating.Replace('.', ',');
try
{
movieDetails.Rating = (float)System.Double.Parse(strRating);
movieDetails.Rating = movieDetails.Rating * 2;
if (movieDetails.Rating > 10.0f)
movieDetails.Rating /= 10.0f;
}
catch (Exception)
{
}
movieDetails.Votes = "0";
///if (movieDetails.Rating != 0.0f)
///{
// now, votes
/// movieDetails.Votes = "0";
/// iStart = strBody.IndexOf("(", iEnd + 2);
/// if (iStart > 0)
/// {
/// iEnd = strBody.IndexOf(" votes</a>)", iStart);
/// if (iEnd > 0)
/// {
/// iStart += "(<a href=\"ratings\">".Length; // skip the parantese and link before votes
/// movieDetails.Votes = strBody.Substring(iStart, iEnd - iStart).Trim();
/// }
/// }
///}
}
}
///if (iTop >= 0) // top rated movie :)
///{
/// iTop += "top 250:".Length + 2; // jump space and #
/// iEnd = strBody.IndexOf("</a>", iTop);
/// string strTop = strBody.Substring(iTop, iEnd - iTop);
/// movieDetails.Top250 = System.Int32.Parse(strTop);
///}
///if (iTagLine >= 0)
///{
/// iTagLine += "Tagline:</h5>".Length;
/// iEnd = strBody.IndexOf("<", iTagLine);
/// movieDetails.TagLine = strBody.Substring(iTagLine, iEnd - iTagLine).Trim();
/// movieDetails.TagLine = MediaPortal.Util.Utils.stripHTMLtags(movieDetails.TagLine);
/// movieDetails.TagLine = HttpUtility.HtmlDecode(movieDetails.TagLine); // Remove HTML entities like ½
///}
if (iPlotSummary >= 0)
{
iPlotSummary += "<span style=\"font-family:Arial, Sans-Serif; font-size:90%; color:#696969\">".Length;
iEnd = strBody.IndexOf("</span>", iPlotSummary);
movieDetails.PlotOutline = strBody.Substring(iPlotSummary, iEnd - iPlotSummary).Trim();
movieDetails.PlotOutline = MediaPortal.Util.Utils.stripHTMLtags(movieDetails.PlotOutline);
movieDetails.PlotOutline = HttpUtility.HtmlDecode(movieDetails.PlotOutline); // remove HTML entities
}
if (iPlotOutline >= 0)
{
iPlotOutline += "<strong class=\"courier\" style=\"font-size:23px; margin-bottom:10px; color:#ff0066; display:block;\">".Length;
iPlotOutline ++;
iEnd = strBody.IndexOf("</strong>", iPlotOutline);
movieDetails.TagLine = strBody.Substring(iPlotOutline, iEnd - iPlotOutline).Trim();
movieDetails.TagLine = MediaPortal.Util.Utils.stripHTMLtags(movieDetails.TagLine);
movieDetails.TagLine = HttpUtility.HtmlDecode(movieDetails.TagLine);
while (movieDetails.TagLine.IndexOf(" ") == 0)
{
movieDetails.TagLine = movieDetails.TagLine.Substring(1);
}
}
if (iPlot >= 0)
{
iPlot += "<p style=\"text-align:justify;\">".Length;
iEnd = strBody.IndexOf("</p>", iPlot);
movieDetails.Plot = strBody.Substring(iPlot, iEnd - iPlot).Trim();
movieDetails.Plot = MediaPortal.Util.Utils.stripHTMLtags(movieDetails.Plot);
movieDetails.Plot = HttpUtility.HtmlDecode(movieDetails.Plot); // remove HTML entities
}
if (iImage >= 0)
{
iImage += "src=\"".Length;
iEnd = strImgBody.IndexOf("\"", iImage);
movieDetails.ThumbURL = strImgBody.Substring(iImage, iEnd - iImage).Trim();
}
//plot (removed)
int iRunTime = strBody.IndexOf(" minuti");
iRunTime = iRunTime - 3;
if (iRunTime > 0)
{
string runtime = "";
runtime = strBody.Substring(iRunTime,3);
try
{
movieDetails.RunTime = Int32.Parse(runtime);
}
catch (Exception) { }
}
int mpaa = strBody.IndexOf("<b>Dizionari</b> (");
if (mpaa > 0)
{
mpaa += "<b>Dizionari</b> ".Length;
mpaa++;
movieDetails.MPARating = strBody.Substring(mpaa, 3);
}
int iCredEnd = strBody.IndexOf("Genere", iCred);
iCredEnd --;
iCred += "Con ".Length;
if (iCred >= 0)
{
string strCast = strBody.Substring(iCred, iCredEnd - iCred);
//movieDetails.Cast += strCast;
strCast = MediaPortal.Util.Utils.stripHTMLtags(strCast).Trim();
strCast = HttpUtility.HtmlDecode(strCast);
strCast = strCast.Substring(0, strCast.Length - 1);
movieDetails.Cast += strCast;
///movieDetails.Cast += strActor;
movieDetails.Cast += "\n";
}
return true;
}
catch (Exception ex)
{
MediaPortal.GUI.Library.Log.Error("exception for mymovies lookup of {0} err:{1} stack:{2}", url.URL, ex.Message, ex.StackTrace);
}
return false;
}
string MediaPortal.Video.Database.IIMDBScriptGrabber.GetName()
{
return "MYMOVIESIT grabber ";
}
string MediaPortal.Video.Database.IIMDBScriptGrabber.GetLanguage()
{
return "IT";
}
private string GetPage(string strURL, string strEncode, out string absoluteUri)
{
string strBody = "";
absoluteUri = String.Empty;
Stream ReceiveStream = null;
StreamReader sr = null;
WebResponse result = null;
try
{
// Make the Webrequest
//Log.Info("IMDB: get page:{0}", strURL);
WebRequest req = WebRequest.Create(strURL);
result = req.GetResponse();
ReceiveStream = result.GetResponseStream();
// Encoding: depends on selected page
Encoding encode = System.Text.Encoding.GetEncoding(strEncode);
sr = new StreamReader(ReceiveStream, encode);
strBody = sr.ReadToEnd();
absoluteUri = result.ResponseUri.AbsoluteUri;
}
catch (Exception)
{
//Log.Error("Error retreiving WebPage: {0} Encoding:{1} err:{2} stack:{3}", strURL, strEncode, ex.Message, ex.StackTrace);
}
finally
{
if (sr != null)
{
try
{
sr.Close();
}
catch (Exception)
{
}
}
if (ReceiveStream != null)
{
try
{
ReceiveStream.Close();
}
catch (Exception)
{
}
}
if (result != null)
{
try
{
result.Close();
}
catch (Exception)
{
}
}
}
return strBody;
} // END GetPage()
string ParseAHREFIMDB(string strBody, int iahref, string strURL)
{
int iStart = strBody.IndexOf("<a href=\"", iahref);
if (iStart < 0)
iStart = strBody.IndexOf("<A HREF=\"", iahref);
if (iStart < 0)
return "";
int iEnd = strBody.IndexOf("</a>", iStart);
if (iEnd < 0)
iEnd = strBody.IndexOf("</A>", iStart);
if (iEnd < 0)
return "";
iStart += "<a href=\"".Length;
int iSep = strBody.IndexOf(">", iStart);
string strurl = strBody.Substring(iStart, (iSep - iStart) - 1);
iSep++;
string strTitle = strBody.Substring(iSep, iEnd - iSep);
strTitle = MediaPortal.Util.Utils.stripHTMLtags(strTitle);
HTMLUtil htmlUtil = new HTMLUtil();
htmlUtil.ConvertHTMLToAnsi(strTitle, out strTitle);
strTitle = strTitle.Trim();
return strTitle.Trim();
}
string ParseGenresIMDB(string strBody, int iGenre, string url)
{
int iStart = strBody.IndexOf("href=\"", iGenre);
if (iStart < 0)
iStart = strBody.IndexOf("HREF=\"", iGenre);
if (iStart < 0)
return "";
int iEnd = strBody.IndexOf("</a>", iStart);
if (iEnd < 0)
iEnd = strBody.IndexOf("</A>", iStart);
if (iEnd < 0)
return "";
iStart = strBody.IndexOf(">", iStart);
iStart++;
string strTitle = strBody.Substring(iStart, iEnd - iStart);
strTitle = MediaPortal.Util.Utils.stripHTMLtags(strTitle);
HTMLUtil htmlUtil = new HTMLUtil();
htmlUtil.ConvertHTMLToAnsi(strTitle, out strTitle);
strTitle = strTitle.Trim();
return strTitle.Trim();
}
}